package com.ruoyi.web.controller.pv;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.pv.domain.PvBookingTime;
import com.ruoyi.pv.service.IPvBookingTimeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 预约时段类型Controller
 *
 * @author zzx
 * @date 2023-03-12
 */
@Api("预约时段类型")
@RestController
@RequestMapping("/pv/time")
public class PvBookingTimeController extends BaseController {
    @Autowired
    private IPvBookingTimeService pvBookingTimeService;

    /**
     * 查询预约时段类型列表
     */
    @PreAuthorize("@ss.hasPermi('pv:time:list')")
    @GetMapping("/list")
    @ApiOperation("查询预约时段类型列表")
    public TableDataInfo list(PvBookingTime pvBookingTime) {
        startPage();
        pvBookingTime.setReservedOne(getDeptId());
        List<PvBookingTime> list = pvBookingTimeService.selectPvBookingTimeList(pvBookingTime);
        return getDataTable(list);
    }

    /**
     * 导出预约时段类型列表
     */
    @PreAuthorize("@ss.hasPermi('pv:time:export')")
    @Log(title = "预约时段类型" , businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PvBookingTime pvBookingTime) {
        pvBookingTime.setReservedOne(getDeptId());
        List<PvBookingTime> list = pvBookingTimeService.selectPvBookingTimeList(pvBookingTime);
        ExcelUtil<PvBookingTime> util = new ExcelUtil<PvBookingTime>(PvBookingTime.class);
        util.exportExcel(response, list, "预约时段类型数据");
    }

    /**
     * 获取预约时段类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('pv:time:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取预约时段类型详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(pvBookingTimeService.selectPvBookingTimeById(id));
    }

    /**
     * 新增预约时段类型
     */
    @PreAuthorize("@ss.hasPermi('pv:time:add')")
    @Log(title = "预约时段类型" , businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增预约时段类型")
    public AjaxResult add(@RequestBody PvBookingTime pvBookingTime) {
        pvBookingTime.setReservedOne(getDeptId());
        return toAjax(pvBookingTimeService.insertPvBookingTime(pvBookingTime));
    }

    /**
     * 修改预约时段类型
     */
    @PreAuthorize("@ss.hasPermi('pv:time:edit')")
    @Log(title = "预约时段类型" , businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改预约时段类型")
    public AjaxResult edit(@RequestBody PvBookingTime pvBookingTime) {
        return toAjax(pvBookingTimeService.updatePvBookingTime(pvBookingTime));
    }

    /**
     * 删除预约时段类型
     */
    @PreAuthorize("@ss.hasPermi('pv:time:remove')")
    @Log(title = "预约时段类型" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation("删除预约时段类型")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(pvBookingTimeService.deletePvBookingTimeByIds(ids));
    }
}
